import { Controller } from "../../mvc/core/Controller";
import { IillustrateController } from "./interfaces/IillustrateController";
import { IllustrateIconBtn } from "../view/illustrate/IllustrateIconBtn";
import { IView } from "../../mvc/interfaces/IView";
import { IllustrateModule } from "../../../modules/IllustrateModule";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../scene/events/PlayerEvent";
import { DataEvent } from "../events/DataEvent";
import { ItemData } from "../resource/info/ItemData";
import { GameProxy } from "../mvc/GameProxy";
import { SIllustrateInfo } from "../../../Message/Game/SIllustrateInfo";
import { IllustratePieceInfo } from "../view/illustrate/IllustratePieceInfo";
import { PulseSharedObject } from "../view/player/PulseSharedObject";
import { ObjCreate } from "../view/common/ObjCreate";
import { GlobalStyle } from "../../common/global/GlobalStyle";
import { Language } from "../../../extend/language/Language";
import { MsgTipInfo } from "../model/MsgTipInfo";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SIllustrateInfoMap } from "../../../Message/Game/SIllustrateInfoMap";
import { IillustrateModule } from "../../../modules/interfaces/IillustrateModule";
import { GTextFiled } from "../../../com/mui/controls/GTextFiled";
type int = number;
//class IllustrateController
    
    export  class IllustrateController extends Controller implements IillustrateController
    {
       

        public get illustrateIcon(): IllustrateIconBtn
        {
            if (this._illustrateIcon == null) 
            {
                this._illustrateIcon = new IllustrateIconBtn();
            }
            return this._illustrateIcon;
        }

        protected /* override */ initView(): IView
        {
            if (this._illustrateMudule == null) 
            {
                this._illustrateMudule = new IllustrateModule();
            }
            return this._illustrateMudule;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.IllustrateModuleOpen, this.onIllustrateModuleOpenHandler);
            Dispatcher.addEventListener(EventName.IllustratePieceActive, this.onIllustrateActiveHandler);
            Dispatcher.addEventListener(EventName.IllustratePieceActiveSuccess, this.onIllustrateActiveSuccessHandler);
            Dispatcher.addEventListener(EventName.IllustrateActivedPieceGet, this.onIllustrateActivedPieceGetHandler);
            Dispatcher.addEventListener(EventName.IllustrateActivedPieceGetSuccess, this.onActivedPieceGetSuccessHandler);
            Dispatcher.addEventListener(EventName.IllustrateRewardGet, this.onIllustrateRewardGetHandler);
            Dispatcher.addEventListener(EventName.IllustrateRewardGetSuccess, this.onIllustrateRewardGetSuccessHandler);
            Dispatcher.addEventListener(EventName.IllustratePieceSelectChange, this.onPieceSelectChangeHandler);
            Dispatcher.addEventListener(EventName.LoginGameSuccess, this.onLoginGameSuccessHandler);
            Dispatcher.addEventListener(EventName.IllustrateItemAdd, this.onIllustrateItemAddHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateIllustrateInfo, this.onIllustrateInfoHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleLevelUpdateHandler);
            return;
        }

        /* internal  */onIllustrateModuleOpenHandler(arg1: DataEvent): void
        {
            var loc1=null;
            if (arg1.data != null) 
            {
                loc1 = arg1.data as ItemData;
            }
            if (view.isHide) 
            {
                view.show();
                if (loc1) 
                {
                    this._illustrateMudule.selectIllustrate(loc1);
                }
            }
            else 
            {
                view.hide();
            }
            return;
        }

        /* internal  */onIllustrateActiveHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as string;
            GameProxy.roleProxy.activeIllustratePiece(loc1);
            return;
        }

        /* internal  */onIllustrateActiveSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data;
            var loc2=loc1.illustrateInfo as SIllustrateInfo;
            var loc3=loc1.attrInfo as Map<any, any> /* flash.utils.Dictionary */;
            cache.illustrate.illustrateActiveInfo = loc2;
            cache.illustrate.illustrateAttrInfo = loc3;
            if (this._illustrateMudule && !this._illustrateMudule.isHide) 
            {
                this._illustrateMudule.updateIllustratePieceState();
                this._illustrateMudule.updateAttributeTips();
                this._illustrateMudule.activeUpdatePiece();
            }
            return;
        }

        /* internal  */onIllustrateActivedPieceGetHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            GameProxy.roleProxy.getActivedPiece(loc1);
            return;
        }

        /* internal  */onActivedPieceGetSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SIllustrateInfo;
            cache.illustrate.illustrateActiveInfo = loc1;
            if (this._illustrateMudule && !this._illustrateMudule.isHide) 
            {
                this._illustrateMudule.updateIllustratePieceState();
            }
            return;
        }

        /* internal  */onIllustrateRewardGetHandler(arg1: DataEvent): void
        {
            GameProxy.roleProxy.getRewardAttrInfo();
            return;
        }

        /* internal  */onIllustrateRewardGetSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as Map<any, any> /* flash.utils.Dictionary */;
            cache.illustrate.illustrateAttrInfo = loc1;
            if (this._illustrateMudule && !this._illustrateMudule.isHide) 
            {
                this._illustrateMudule.updateAttributeTips();
            }
            return;
        }

        /* internal  */onPieceSelectChangeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as IllustratePieceInfo;
            if (this._illustrateMudule && !this._illustrateMudule.isHide) 
            {
                this._illustrateMudule.updatePiecePanelInfo(loc1);
            }
            return;
        }

        /* internal  */onLoginGameSuccessHandler(arg1: DataEvent): void
        {
            if (cache.role.entityInfo.level >= 40) 
            {
                this.illustrateIcon.show();
            }
            return;
        }

        /* internal  */onIllustrateItemAddHandler(arg1: DataEvent): void
        {
            var loc1=null;
            this._tipItem = arg1.data as ItemData;
            if (cache.illustrate.isCanActiveIllustrate(this._tipItem) && !PulseSharedObject.isTodayNotTips("IllustrateNotTipToday")) 
            {
                if (this._contentTxt == null) 
                {
                    this._contentTxt = ObjCreate.createGTextField("", 0, 0, 200, 60, null, GlobalStyle.textFormat6);
                    this._contentTxt.multiline = true;
                    this._contentTxt.wordWrap = true;
                    this._contentTxt.htmlText = Language.getString(36320);
                    this._contentTxt.addEventListener(flash.events.TextEvent.LINK, this.onContentTxtHandler);
                }
                loc1 = new MsgTipInfo();
                loc1.type = 1;
                loc1.isAutoHide = true;
                loc1.notTipEvent = "IllustrateNotTipToday";
                loc1.displayObject = this._contentTxt;
                Dispatcher.dispatchEvent(new DataEvent(EventName.MsgTipDateChange, loc1));
            }
            if (this._illustrateMudule && !this._illustrateMudule.isHide) 
            {
                this._illustrateMudule.updateIllustratePieceState();
            }
            return;
        }

        /* internal  */onContentTxtHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (view.isHide) 
            {
                view.show();
                if (this._tipItem) 
                {
                    this._illustrateMudule.selectIllustrate(this._tipItem);
                    this._tipItem = null;
                }
            }
            return;
        }

        /* internal  */onIllustrateInfoHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SIllustrateInfoMap;
            cache.illustrate.illustrateMap = loc1.infoMap;
            return;
        }

        /* internal  */serverBagDataChangehandler(arg1: Object): void
        {
            if (this._illustrateMudule && !this._illustrateMudule.isHide) 
            {
                this._illustrateMudule.updateIllustratePieceState();
            }
            return;
        }

        /* internal  */onRoleLevelUpdateHandler(arg1: Object): void
        {
            if (cache.role.entityInfo.level >= 40) 
            {
                if (!this._illustrateIcon) 
                {
                    this.illustrateIcon.show();
                }
                if (this._illustrateMudule && !this._illustrateMudule.isHide) 
                {
                    this._illustrateMudule.updateListByLevelUpdate();
                }
            }
            return;
        }

        private /* var */_illustrateMudule: IillustrateModule;

        private /* var */_illustrateIcon: IllustrateIconBtn;

        private /* var */_contentTxt: GTextFiled;

        private /* var */_tipItem: ItemData;
    }
